package main

import (
	"fmt"
	"strconv"
)

var globalvar = "global string"

type Books struct {
	title   string
	author  string
	subject string
	book_id int
}

func main() {
	for i := 1; i < 10; i++ {
		if i%2 == 0 {
			tmp := "hello world\t" + strconv.Itoa(i)
			fmt.Println(tmp)
		}
	}
	var a [100]int
	for i := 0; i < 10; i++ {
		a[i] = i
		fmt.Println(strconv.Itoa(a[i]))
	}

	//另外一种循环
	i := 0
	for {
		if i > 10 {
			break
		}
		fmt.Println(i)
		i++
	}
	fmt.Println(globalvar)

	var balance [5]float32 = [...]float32{1000.0, 2.0, 3.4, 7.0, 50.0}
	for i := 0; i < 5; i++ {
		fmt.Println(balance[i])
	}

	book := Books{"标题：Augular技术实践", "作者：张三", "科目：计算机技术", 12}
	fmt.Println(book)
	printBook(book)

	//下面是错的。
	//var sli [5]int = [...]int{1, 2, 3}
	var sli []int = []int{1, 2, 3}
	fmt.Println(sli)

	//这是我们使用range去求一个slice的和。使用数组跟这个很类似
	nums := []int{2, 3, 4}
	sum := 0
	for _, num := range nums {
		sum += num
	}
	fmt.Println(sum)

	tmp := make([]int, 11, 11)
	fmt.Println(tmp)
}

func printBook(book Books) {
	fmt.Printf("书的标题是：%s\n", book.title)
	fmt.Printf("书的作者是：%s\n", book.author)
	fmt.Printf("书的科目是：%s\n", book.subject)
	fmt.Printf("书的是：%d\n", book.book_id)
}
